<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- 动态切换图标 全屏: exit-fullscreen 不是全屏: fullscreen -->
    <svg-icon
      :icon-class="isScreenFull ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="toggleScreen"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data () {
    return {
      isScreenFull: false // 是否全屏
    }
  },
  methods: {
    toggleScreen () {
      // console.log(screenfull.isEnabled) // 布尔值
      // // 判断是否可用
      if (!screenfull.isEnabled) {
        // 此时全屏不可用
        this.$message.warning('此时全屏组件不可用')
        return
      }
      //   如果可用 就可以全屏
      screenfull.toggle()
      this.isScreenFull = !this.isScreenFull
    }
  }
}

</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
